<?php

require_once "../vendor/autoload.php";

class UserDto extends \Reusify\Dto\BaseDto
{
    public int $id;
    public string $name;
    public string $email;
    public string $password;

}


$userDto = new UserDto([
    'id' => 1,
]);

echo $userDto;
//输出为 {"id":1}
var_dump($userDto->toArray());//['id'=>1]
var_dump($userDto->toJson());//{"id":1}

$array = [];
$array[] = $userDto;
$array[] = $userDto;
$r = array_column($array, 'id');
var_dump($r);//结果为 [1,1]


$userDto = new UserDto([
    'id' => 1,
    'name' => 'test',
    'email' => 'email',
    'password' => 'password',
]);

class AdminDto extends \Reusify\Dto\BaseDto
{
    public int $id;
    public string $name;
    public string $email;
    public string $password;
}


$adminDto = new AdminDto($userDto);

echo $adminDto;//{"id":1,"name":"test","email":"email","password":"password"}

$userDto = new UserDto([
    'id' => 1,
    'name' => 'test',
    'email' => 'email',
    //'password' => 'password',
]);

$adminDto1 = new AdminDto($userDto,['name'=>'email']);

echo $adminDto1;//}{"id":1,"name":"email","email":"email"}